package Dao;

import Table.Book;
import Utils.DruidUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class InsertBookDao {
    public static Boolean Insert(Book book) {
        Connection conn = null;
        PreparedStatement pstmt = null;
        try {
            conn = DruidUtils.getConnection();
            String sql = "insert into book value (?,?,?,?,?)";
            pstmt = conn.prepareStatement(sql);
            pstmt.setInt(1, book.getId());
            pstmt.setString(2, book.getBookname());
            pstmt.setString(3, book.getAuther());
            pstmt.setInt(4, book.getPrice());
            pstmt.setInt(5, book.getNums());
            int i = pstmt.executeUpdate();
            if (i > 0) {
                return true;
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } finally {
            DruidUtils.close(pstmt, conn);
        }
        return false;
    }
}
